using System.Collections.Generic;
using System.ServiceModel.Syndication;
using aprogblog.Domain;
using aprogblog.Domain.Classes;
using aprogblog.Domain.Helpers;
using aprogblog.Specs.Helpers;
using FluentSpec;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;

namespace aprogblog.Specs {
    
    [TestClass]
    public class when_reading_recent_Entries {
        
        const int RequestedNumberOfEntries = 3;
        
        [TestClass]
        public class a_WeblogService : BehaviorOfWeblogService {
        
            [TestMethod]
            public void should_get_them_from_the_Blog() {
            
                Blog.Given().RecentEntries(RequestedNumberOfEntries)
                    .Are(Actors.ThreeEntries);
                
                When.GetRecentPosts(null, null, null, RequestedNumberOfEntries)
                    .Length.ShouldBe(RequestedNumberOfEntries);
            }
        }
        
        [TestClass]
        public class a_Blog : BehaviorOf<BlogClass> {
            
            List<Entry> TheRecentEntries;
            readonly SyndicationFeed FeedWithTwoItems = Actors.FeedWithTwoItems;       

            [TestInitialize]
            public void SetUp() {
                Given.Feed.Is(FeedWithTwoItems);
                TheRecentEntries = The.RecentEntries(RequestedNumberOfEntries);
            }

            [TestMethod]
            public void should_not_return_more_than_requested() {

                TheRecentEntries.Count.ShouldBeLessOrEqual(RequestedNumberOfEntries);
            }
            
            [TestMethod]
            public void should_return_the_newest_first() {
                var TheNewestEntry = TheRecentEntries.First();
                var TheLastEntryInTheFeed = FeedWithTwoItems.Items.Last().ToEntry();
                
                TheNewestEntry.ShouldBe(TheLastEntryInTheFeed);
            }
        }        
    }
}